/*
		PandaForum: PHP Forum Engine
		
		Jesse Gill, 0108377707
*/

function createHTTPObject()
{
	// IE7+, Firefox, Chrome, Opera, Safari
	if (window.XMLHttpRequest)
	{
		return new XMLHttpRequest();
	}
	// IE6, IE5
	else if (window.ActiveXObject)
	{
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	// not recognised
	else
	{
		return false;
	}
}

function ajax_login()
{
	var httpObj = createHTTPObject();
	
	if (httpObj == false)
	{
		return;
	}
	
	httpObj.onreadystatechange=function()
	{
		if(httpObj.readyState==4)
		{
			document.getElementById('userbar').innerHTML = httpObj.responseText;
		}
	}
	
	var url = "login.php?username=" + document.loginForm.username.value + "&password=" + document.loginForm.password.value;
	
	httpObj.open("GET", url, true);
	httpObj.send(null);
}

function ajax_logout()
{
	var httpObj = createHTTPObject();
	
	if (httpObj == false)
	{
		return;
	}
	
	httpObj.onreadystatechange=function()
	{
		if(httpObj.readyState==4)
		{
			document.getElementById('userbar').innerHTML = httpObj.responseText;
		}
	}
	
	httpObj.open("GET", "logout.php", true);
	httpObj.send(null);
}

function ajax_register()
{
	var httpObj = createHTTPObject();
	
	if (httpObj == false)
	{
		return;
	}
	
	httpObj.onreadystatechange=function()
	{
		if(httpObj.readyState==4)
		{
			document.getElementById('register_response_area').innerHTML = httpObj.responseText;
		}
	}
	
	var url = "register_db.php?username=" + document.registerForm.username.value + "&password=" + document.registerForm.password.value;
	url += "&retypepassword=" + document.registerForm.retypepassword.value + "&email=" + document.registerForm.email.value;
	url += "&day=" + document.registerForm.day.value + "&month=" + document.registerForm.month.value;
	url += "&year=" + document.registerForm.year.value;
	
	httpObj.open("GET", url, true);
	httpObj.send(null);
}
